package communicationMessages;

import java.util.logging.Level;

import logger.LoggerWriter;
import database.DB;

public class AddModeratorMessage extends Message {

	@Override
	public String getAnswer() {
		String[] arr = this.content.split(delimiter);
		LoggerWriter logger = LoggerWriter.getLoggerWriter();
		String ans = "ModeratorAdded"+delimiter;
		if (arr.length != 3)
		{
			logger.log("failed"+delimiter+"Add Moderator Message wrong format"+delimiter, Level.WARNING);
			ans = "failed"+delimiter+"Add Moderator Message wrong format"+delimiter;
		}
		else
		{
			String userName , moderatorUserName ,subForumID ;
			userName = arr[0];
			moderatorUserName = arr[1];
			subForumID = arr[2];
			int moderatorID = DB.getUserId(moderatorUserName);
			if (DB.isAdmin(userName) && DB.isSubForumExist(subForumID) && moderatorID > 0 && DB.canBeModerator(subForumID,moderatorID))
			{
				DB.addModerator(subForumID,moderatorID);
				ans = "addedModerator" + delimiter + DB.getUserRoll(userName)+delimiter+"Success"+delimiter;
			}
			else
			{
				ans = "addedModerator" + delimiter + DB.getUserRoll(userName)+delimiter+"Failed"+delimiter;
			}
				
		} 
		return ans;
	}
}

/*else
{
	String userName , moderatorUserName ,subForumID ;
	userName = arr[0];
	moderatorUserName = arr[1];
	subForumID = arr[2];
	Vector<Integer> path = new Vector<Integer>();
	Integer subForumInt = Integer.valueOf(subForumID);
	path.add(subForumInt);
	Forum forum = Forum.getForum();
	SubForum subforum = forum.getSubForum(subForumInt);
	if(subforum.addModerator(moderatorUserName))
		ans = "addedModerator" + delimiter + MemberDataBase.getUserRoll(userName)+delimiter+"Success"+delimiter;
	else ans = "addedModerator" + delimiter + MemberDataBase.getUserRoll(userName)+delimiter+"Failed"+delimiter;
		
} */
